window.onload = function(){
    TabBar('order');
    axios.defaults.withCredentials = true;
    //获取用户登录
    axios.get('https://elm.cangdu.org/v1/user').then(res => {
    console.log(res);
     //获取订单列表了
     $().ajax({
        url:`https://elm.cangdu.org/bos/v2/users/${res.data.id}/orders?limit=10&offset=0`,
        method:'GET',
        async:true,
        success:data=>{
            console.log(data);
            var text=''
           
            for (let i = 0; i < data.length; i++) {
            
                $create('kh_showorder','kh_showodera',
                `<div class='kh_flex'>
                <div class="kh_orderimg">
                <img src='//elm.cangdu.org/img/${data[i].restaurant_image_url}'>
                </div>
                <div class='kh_fontname'><span>${data[i].restaurant_name}></span><br>
                <span class='kh_timerwidth'>${data[i].formatted_created_at}</span>
                
                </div>
                <div class='kh_zfcs'>
                ${data[i].status_bar.title}
                </div>
                </div>
                <div class='kh_flex'>
                <div class='kh_orderimg'></div>
                <div class='kh_goods'>
                ${data[i].basket.group[0][0].name}等  ${data[i].basket.group[0].length}件商品
                </div>
                <div class='kh_total_amount'>
                ￥${data[i].total_amount}
                </div>
                </div>
                <div >
                <div class='kh_onemore'>
                再来一单
                </div>
                </div>
                
              `
                )
           
            }
            let kh_onemore=document.getElementsByClassName("kh_onemore")
            for (let i = 0; i < data.length; i++) {
                kh_onemore[i].addEventListener('click',()=>{
                   
                    window.location.href=`/pages/restaurant/restaurant.html?id=${data[i].restaurant_id}`
                })
                
            }
            let kh_showodera=document.getElementsByClassName("kh_showodera")
            for (let i = 0; i < data.length; i++) {
                kh_showodera[i].addEventListener('click',function(){
                    window.location.href=`/pages/orderxq/orderxq.html?order_id=${data[i].id}&user_id=${res.data.id}`
                })
                
            }

            
           
        }
    })
    })
   
  
}